import { baseURL } from './base.js'
export function uploadtempFile(path) {
 	return new Promise((resolve, reject) => {
		const tok = uni.getStorageSync('token');
 		uni.uploadFile({
 			url: `${baseURL}/app-api/infra/file/upload`,
 			filePath: path,
 			name: 'file',
 			header: {
 				"authorization": "Bearer " + tok,
				"tenant-id":"1",
				// "Content-Type": "application/json;charset=UTF-8"
 			},
			 
 			success(res) {
 				var data = JSON.parse(res.data)
 				if (data.code ===0) {
 					resolve(data.data)
 				}else if(data.code == 401){
					uni.reLaunch({
						url:'/pages/login/login'
					})	
				} else {
 					reject(data.msg);
 				}
				 
 			},
 			fail(err) {
 				reject(err);
				 
 			} 
			 
 		})
 	})
 }
export function uploadvideo(path) {
 	return new Promise((resolve, reject) => {
		const tok = uni.getStorageSync('token');
		uni.chooseVideo({
		  count: 1,
		  sourceType: ["camera","album"],
		  success(rest) {
			  uni.showLoading({
			    title: "视频上传中",
			  });
			var filePath=rest.tempFilePath
			uni.uploadFile({
					url: `${baseURL}/api/upload/video`,
					filePath,
					name: 'video',
					 
					formData: {
						'token': tok
					},
					success(uploadFileRes) {
						var data = JSON.parse(uploadFileRes.data)
						if (data.code == 200) {
							if ("string" === typeof uploadFileRes.data) {
							  resolve(JSON.parse(uploadFileRes.data).data);
							} else {
							  resolve(uploadFileRes.data.data);
							}

						}else if(data.code == 401){
							uni.reLaunch({
								url:'/pages/index/index'
							})	
						}else {
							reject(res);
						}
						 uni.hideLoading();
					},
					fail(err) {
						reject(err);
						uni.hideLoading(); 
					} 
					 
				})
			
		  },
		  fail(err) {
			console.log(err);
			reject(err);
		  },
		});
	})
 }
